package com.zls.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zls.pojo.SysUser;
import com.zls.pojo.TDevice;
import com.zls.pojo.TDeviceType;
import com.zls.pojo.TFarm;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface TDeviceMapper extends BaseMapper<TDevice> {
    @Results(id = "tdeviceMap", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "sn", property = "sn"),
            @Result(column = "name", property = "name"),
            @Result(column = "type_id", property = "typeId"),
            @Result(column = "farm_id", property = "farmId"),
            @Result(column = "location", property = "location"),
            @Result(column = "install_time", property = "installTime"),
            @Result(column = "state", property = "state"),
            @Result(column = "standard", property = "standard"),
            @Result(column = "manufacturer", property = "manufacturer"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "software_version", property = "softwareVersion"),
            @Result(column = "threshold_min", property = "thresholdMin"),
            @Result(column = "threshold_max", property = "thresholdMax"),
            @Result(column = "remark", property = "remark"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "operator", property = "operator"),
            @Result(column = "farm_id", property = "tFarm", javaType = TFarm.class, one =
            @One(select = "com.zls.mapper.TFarmMapper.selectId", fetchType = FetchType.EAGER)),
            @Result(column = "type_id", property = "tDeviceType", javaType = TDeviceType.class, one =
            @One(select = "com.zls.mapper.TDeviceTypeMapper.selectById", fetchType = FetchType.EAGER))
    })
    @Select("<script>" +
            "select * from t_device where 1=1" +
            "<if test='queryString!=null'> and name like concat( '%',#{queryString},'%')" +
            "limit #{currentPage},#{pageSize}</if>" +
            "<if test='queryString==null'>limit #{currentPage},#{pageSize}</if> "+
            "</script>")
    List<TDevice> findPage(@Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize, @Param("queryString") String queryString);

    //查询总记录数
    @Select("<script>" +
            "select count(*) from t_device where 1 =1" +
            "<if test='queryString!=null'> and name like concat( '%',#{queryString},'%') </if>" +
            "</script>")
    Long count(String queryString);

    @ResultMap("tdeviceMap")
    @Select("select * from t_device where id=#{id}")
    TDevice findById(int id);


    @Select("select id from t_device")
    List<Integer> findIds();
}
